<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['manager:qrcode_information:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['manager:qrcode_information:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['manager:qrcode_information:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manager:qrcode_information:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="qrcode_informationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="内容" align="center" prop="content" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manager:qrcode_information:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manager:qrcode_information:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改扫码报警临时信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" :width="title == '修改扫码报警临时信息' ? '900px' : '600px'" append-to-body style="margin-top: 50px;">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="内容" prop="content">
          <el-input v-model="form.content" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <el-button v-if="title == '修改扫码报警临时信息'" type="primary" @click="contentfocus">添加二维码</el-button>
      <el-table v-if="title == '修改扫码报警临时信息'" v-loading="loading" :data="List" style="max-height: 400px;overflow-y: auto;">
	      <el-table-column label="唯一编码值" align="center" prop="code" />
	      <el-table-column label="高速公路" align="center" prop="expressWayName" />
	      <el-table-column label="桩号千米" align="center" prop="expressWayKil" />
	      <el-table-column label="桩号米数" align="center" prop="expressWayMeter" />
	      <el-table-column label="方向类型" align="center" prop="direction" :formatter="directionFormat" />
	      <el-table-column label="提醒内容" align="center" prop="remindContent" />
	      <el-table-column label="二维码状态" align="center" prop="status" :formatter="statusFormat" />
	      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
	        <template slot-scope="scope">
	          <el-button
	            size="mini"
	            type="text"
	            icon="el-icon-delete"
	            @click="handleDeletecode(scope.row)"
	          >删除</el-button>
	        </template>
	      </el-table-column>
	    </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="添加二维码" :visible.sync="openadd" width="1000px" append-to-body>
      <el-form :model="codequeryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
	      <el-form-item label="唯一编码值" prop="code">
	        <el-input
	          v-model="codequeryParams.code"
	          placeholder="请输入唯一编码值"
	          clearable
	          size="small"
	          @keyup.enter.native="handleQuery"
	        />
	      </el-form-item>
	      <el-form-item label="高速公路" prop="expressWayName">
	        <el-input
	          v-model="codequeryParams.expressWayName"
	          placeholder="请输入高速公路"
	          clearable
	          size="small"
	          @keyup.enter.native="handleQuery"
	        />
	      </el-form-item>
	      <el-form-item label="桩号千米" prop="expressWayKil">
	        <el-input
	          v-model="codequeryParams.expressWayKil"
	          placeholder="请输入桩号千米"
	          clearable
	          type="number"
	          size="small"
	          @keyup.enter.native="handleQuery"
	        />
	      </el-form-item>
	      <el-form-item label="桩号米数" prop="expressWayMeter">
	        <el-input
	          v-model="codequeryParams.expressWayMeter"
	          placeholder="请输入桩号米数"
	          clearable
	          type="number"
	          size="small"
	          @keyup.enter.native="handleQuery"
	        />
	      </el-form-item>
	      <el-form-item label="方向类型" prop="direction">
	        <el-select v-model="codequeryParams.direction" placeholder="请选择方向类型" clearable size="small">
	          <el-option
	            v-for="dict in directionOptions"
	            :key="dict.dictValue"
	            :label="dict.dictLabel"
	            :value="dict.dictValue"
	          />
	        </el-select>
	      </el-form-item>
	      <el-form-item label="二维码状态" prop="status">
	        <el-select v-model="codequeryParams.status" placeholder="请选择二维码状态" clearable size="small">
	          <el-option
	            v-for="dict in statusOptions"
	            :key="dict.dictValue"
	            :label="dict.dictLabel"
	            :value="dict.dictValue"
	          />
	        </el-select>
	      </el-form-item>
	      <el-form-item>
	        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuerycode">搜索</el-button>
	        <el-button icon="el-icon-refresh" size="mini" @click="resetQuerycode">重置</el-button>
	      </el-form-item>
	    </el-form>
      <el-table v-loading="loading" :data="InformationList" @selection-change="handleSelection" style="max-height: 450px;overflow-y: auto;">
      	<el-table-column type="selection" width="55" align="center" />
	      <el-table-column label="唯一编码值" align="center" prop="code" />
	      <el-table-column label="高速公路" align="center" prop="expressWayName" />
	      <el-table-column label="桩号千米" align="center" prop="expressWayKil" />
	      <el-table-column label="桩号米数" align="center" prop="expressWayMeter" />
	      <el-table-column label="方向类型" align="center" prop="direction" :formatter="directionFormat" />
	      <el-table-column label="提醒内容" align="center" prop="remindContent" />
	      <el-table-column label="二维码状态" align="center" prop="status" :formatter="statusFormat" />
	    </el-table>
	    <pagination
	      v-show="total1>0"
	      :total="total1"
	      :page.sync="codequeryParams.pageNum"
	      :limit.sync="codequeryParams.pageSize"
	      @pagination="getdata"
	    />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormadd">确 定</el-button>
        <el-button @click="canceladd">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listQrcode_information, getQrcode_information, delQrcode_information, addQrcode_information, updateQrcode_information, exportQrcode_information, listByTemporaryInformationId, insertCallPoliceAndRelevance, removeCallPolice } from "@/api/callPolice/qrcode_information";

export default {
  name: "Qrcode_information",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 扫码报警临时信息表格数据
      qrcode_informationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        content: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      openadd: false,
      InformationList: [],
      addids: [],
			List: [],
			directionOptions: [],
			statusOptions: [],
			Updateid: '',
      codequeryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        expressWayName: null,
        expressWayKil: null,
        expressWayMeter: null,
        direction: null,
        remindContent: null,
        status: null,
      },
      total1: 0,
    };
  },
  created() {
    this.getList();
    this.getDicts("qrcode_direction").then(response => {
      this.directionOptions = response.data;
    });
    this.getDicts("qrcode_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询扫码报警临时信息列表 */
    getList() {
      this.loading = true;
      listQrcode_information(this.queryParams).then(response => {
        this.qrcode_informationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getdata(){   	
    	this.loading = true;
      listByTemporaryInformationId(this.codequeryParams).then(response => {
        this.InformationList = response.rows;
        this.total1 = response.total;
        this.loading = false;
      });
    },
    submitFormadd(){
    	this.openadd = false;
      console.log(this.addids)
      insertCallPoliceAndRelevance({
      	"id": this.Updateid,
 				"callPoliceQrcodeIdList": this.addids
      }).then(response => {
        this.Refresh();
      });
    },
    Refresh(){
    	getQrcode_information(this.Updateid).then(response => {
        this.form = response.data;
        this.List = response.data.callPoliceTemporaryInformationList
      });
    },
    canceladd(){
    	this.openadd = false;
    	this.addids - [];
    },
    contentfocus(){
    	this.openadd = true;
      this.getdata();
    },
    handleDeletecode(row){
    	this.$confirm('是否确认删除数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return removeCallPolice(row.id);
      }).then(() => {
      	this.Refresh();
        this.msgSuccess("删除成功");
      })
    },
    // 方向类型 1:上行，2：下行字典翻译
    directionFormat(row, column) {
      return this.selectDictLabel(this.directionOptions, row.direction);
    },
    // 二维码状态 1，启用，0，未启用，2，未下载制作，3已下载制作字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        content: null,
        createTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuerycode() {
      this.codequeryParams.pageNum = 1;
      this.getdata();
    },
    /** 重置按钮操作 */
    resetQuerycode() {
      this.resetForm("queryFormcode");
      this.handleQuerycode();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleSelection(selection) {
      this.addids = selection.map(item => item.id);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加扫码报警临时信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.Updateid = id;
      getQrcode_information(id).then(response => {
        this.form = response.data;
        this.List = response.data.callPoliceTemporaryInformationList
        this.open = true;
        this.title = "修改扫码报警临时信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateQrcode_information(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addQrcode_information(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除扫码报警临时信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delQrcode_information(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有扫码报警临时信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportQrcode_information(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
